package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Programme;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ProgrammeService;
import org.hxyjs.vo.ProgrammeView;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.cloud.openfeign.SpringQueryMap;
import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 programmeController
//@RequestMapping("/programmeController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /programmeController
public class ProgrammeController {
	@Resource
    ProgrammeService programmeService;

	@GetMapping("/programmes")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Programme> getAllProgramme() throws Exception{
    	System.out.println("查询全部专家");
    	return programmeService.getAllProgrammes();
    }

	@PostMapping("/programme")
	@ResponseBody
	public DTO<Programme> addProgramme(@RequestBody Programme programme) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加专家成功");
		return programmeService.addProgramme(programme);
	}
	@DeleteMapping("/programme/{prno}")
	@ResponseBody
    public DTO<Programme> deleteProgrammeByPrno(@RequestBody @PathVariable("prno") String prno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(prno+"删除专家成功");
    	return programmeService.deleteProgrammeByPrno(prno);
    }

	@GetMapping("/programme/{prno}")
	@ResponseBody
	public DTO<Programme> getProgrammeByPrno(@PathVariable("prno") String prno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(prno+"根据主键查询专家成功");
		return programmeService.getProgrammeByPrno(prno);
	}

	@PatchMapping("/programme")
	@ResponseBody
	public DTO<Programme> updateProgrammeByPrno(@RequestBody ProgrammeView programmeView) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改专家成功");
		return programmeService.updateProgrammeByPrno(programmeView);
	}

	@RequestMapping("/programmes/pageInfo")
	@ResponseBody
	public DTO<Programme> getProgrammeByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return programmeService.getProgrammeByPage(pageInfo);
	}

}
